/*
 * Port_Config.c
 *
 *  Created on: Nov 5, 2013
 *      Author: BlackVolt
 */



#include "derivative.h" /* include peripheral declarations */
#include "MyTypes.h"
#include "Port_Config.h"


void vdfn_Port_Config(){

	
	//***************CLOCK ENABLE PORT ************************
	PORT_A_CLK_EN;			// PORT C
	PORT_B_CLK_EN			// PORT B
	PORT_C_CLK_EN;			// PORT A
	PORT_D_CLK_EN;			// PORT D 
	PORT_E_CLK_EN;			// PORT E For HBridge Enable and Camera CLK
	
	//PORTC_PCR3 |= PORT_PCR_MUX(5);	SIM_SOPT2 |= SIM_SOPT2_CLKOUTSEL(2); //CLKOUT
	
	
	//***************** H_BRIDGE ********************************
	
	PORTE_PCR21 = PORT_PCR_MUX(3); 	// Select as GPIO and Digital OUTPUT
		
	GPIOE_PDDR |= (OUTPUT << 21);

	//H_BRIDGE_DIS;
	
	
	//**************PWM ENABLE PORT******************************
	
	//PIN Enable
	PORTC_PCR1 = PORT_PCR_MUX(4); 	//TPM0_CH0
    PORTC_PCR2 = PORT_PCR_MUX(4);   //TPM0_CH1
    PORTC_PCR3 = PORT_PCR_MUX(4);   //TPM0_CH2
    PORTC_PCR4 = PORT_PCR_MUX(4);	//TPM0_CH3
	
	//Input/Output Config
	GPIOC_PDDR |= (OUTPUT << TPM0_CH0) | (OUTPUT << TPM0_CH1) | (OUTPUT << TPM0_CH2) | (OUTPUT << TPM0_CH3);
	
	
	//**************** PUSH BUTTON	*****************************
	
	//PIN enable
	PORTC_PCR13 = PORT_PCR_MUX(1);    //GPIO - SW1
	PORTC_PCR17 = PORT_PCR_MUX(1); 	  //GPIO - SW2
	
	//INPUT config
	GPIOC_PDDR |= (INPUT << PUSH_BUTT0N_0) | (INPUT << PUSH_BUTT0N_1);
	
	
	//**************** LEDS ************************************
	// Pin Enable
	PORTB_PCR8  = PORT_PCR_MUX(1); 	//LED1
	PORTB_PCR9  = PORT_PCR_MUX(1);  //LED2
	PORTB_PCR10 = PORT_PCR_MUX(1);  //LED3
	PORTB_PCR11 = PORT_PCR_MUX(1);	//LED4
	
	//Set Output PIN
	GPIOB_PDDR |= (OUTPUT << LED1) |(OUTPUT << LED2) |(OUTPUT << LED3) |(OUTPUT << LED4);
		
	
	
	//************** INPUT CAPTURE PORT**************************
	//PIN Enable
	PORTA_PCR1 = PORT_PCR_MUX(3);
	
	//Input/Output Config
	GPIOC_PDDR |= (INPUT << 1);
	
	//************** ADC **************************
	//Pin Enable
	PORTD_PCR5 = PORT_PCR_MUX(0); //ADC_SE6B
	PORTD_PCR6 = PORT_PCR_MUX(0); //ADC_SE7B
	
	//Input/Output Config
	GPIOB_PDDR |= (INPUT << ADC_CH0_SE6B) | (INPUT << ADC_CH0_SE7B);
	
	
	//******************** CAMERA *******************************//

	/* Clock Gating for SPI (Camera Clock) is at Camera Init */
	//PORTE_PCR2 = PORT_PCR_MUX(2);
	//GPIOE_PDDR |= (OUTPUT << CAMERA_CLOCK);
	
	PORTE_PCR1 = PORT_PCR_MUX(1); //2 SPI1 SCK
	GPIOE_PDDR |= (OUTPUT << 1);
	PORTD_PCR7 = PORT_PCR_MUX(1); //GPIO (Camera Enable)
	GPIOD_PDDR |= (OUTPUT << 7);
	
			
	//************** Bus CLK Test *******************************
	/*SIM_SOPT2 |= SIM_SOPT2_CLKOUTSEL(2);
	PORTC_PCR3 = PORT_PCR_MUX(5);
	GPIOC_PDDR |= (OUTPUT << 3);
	*/ //Uncomment if Bus Clock needs to be shown at port C.
	

	//************ SERVO MOTOR **********************************//
	PORTB_PCR0  = PORT_PCR_MUX(3); 	//SERVO MOTOR
	
	GPIOB_PDDR |= (OUTPUT << SERVO_MOTOR);
	
	
	
}

